package cn.uway.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import cn.uway.netty.server.TcpServer;
import cn.uway.properties.TcpServerProperties;



@Component
public class ContextListener implements ApplicationListener<ApplicationReadyEvent> {

	protected Logger log = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private  TcpServerProperties tcpServerProperties;
	
    @Override
    public void onApplicationEvent(final ApplicationReadyEvent event) {
    	Integer port = tcpServerProperties.getPort();
    	if(port!=null){
    		new TcpServer(port).start();
        	log.debug("ContextListener.onApplicationEvent TcpServer 线程启动完成！");
    	}
    	else{
    		log.debug("ContextListener.onApplicationEvent Tcp 端口没有配置");
    	}    	
    }
    
}
